<%--
  Created by IntelliJ IDEA.
  User: YJ
  Date: 2021/4/8
  Time: 20:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>


<form id="f">
    <p>用户名：<input type="text" name="userName"></p>
    <p>密&nbsp;&nbsp;&nbsp;码：<input type="password" name="userPassword"></p>
    <p><input type="submit" onclick="fun(this)" value="登录"></p>
</form>


<script type="text/javascript" src="../js/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
    function fun(){
        $.ajax({
            type:"GET",
            url:"/tbUser/queryAll",
            contentType:"application/json",
            data:$("#f").serialize(),
            // async:false,
            success:function (res){
                // console.log("****************************")
                console.log(res)
                if (res.userId==null){
                    alert("用户名或密码错误！！！")
                }else {
                    // console.log(res)
                    sessionStorage.setItem("user",JSON.stringify(res))
                    location.href="/html/04-cart.jsp"
                    // console.log("取出session")
                    // console.log(JSON.parse(sessionStorage.getItem("user")))
                }
            }
        });
    }
</script>



</body>
</html>
